package com.swinw.asumall.client.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Controller
public class UserController {

    /**
     * 业务代码，如果用户没有登录，那么就不能访问
     * @param model
     * @return
     */
    @GetMapping("/userlist")
    public String userList(Model model,
                           HttpSession session,
                           @RequestParam(value = "token",required = false)String token){
        if(!StringUtils.isEmpty(token)){//用户已经登录
            session.setAttribute("userlogin","张三");
        }
        Object attribute = session.getAttribute("userlogin");
        if(attribute == null){
            return "redirect:http://sso.com:8080/login?redirectUrl=http://client1.com:8081/userlist";
        }else{
            ArrayList<String> list = new ArrayList<>();
            list.add("张三");
            list.add("李四");
            list.add("翠花");
            model.addAttribute("list",list);
            return "list";
        }

    }

}
